package bean;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

public class MyValidator implements Validator {

	@Override
	public void validate(FacesContext context, UIComponent component,
			Object value) throws ValidatorException {
		
		if(String.valueOf(value).length()<3){
			
			HtmlInputText inputText =  (HtmlInputText) component;
			FacesMessage message = new FacesMessage(inputText.getLabel() + " : minimum 3 characters required!");
			throw new ValidatorException(message);
		
		}

	}

}
